﻿namespace WMS6.Services
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.ServiceModel.Activation;
    using WMS6.BLL;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.QueryEntity;

    [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class InboundService : IInboundService
    {
        public string BatchExecutePalletizing(List<string> receiptID, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptDetailLpnBLL(pubParasInfo).BatchExecutePalletizing(receiptID);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_BatchPalletizing_Receipt", receiptID, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string BatchRevertPalletizing(List<string> receiptID, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptDetailLpnBLL(pubParasInfo).BatchRevertPalletizing(receiptID);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_BatchUnPalletizing_Receipt", receiptID, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string CheckPoIsGeneratedASN(string PoID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new ReceiptBLL(pubParasInfo).CheckPoIsGeneratedASN(PoID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return temp;
        }

        public string CloseReceipt(List<string> receiptIDS, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptBLL(pubParasInfo).CloseReceipt(receiptIDS);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Close_Receipt", receiptIDS, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string DeleteReceiptInfo(List<string> receiptIDS, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptBLL(pubParasInfo).DeleteReceipt(receiptIDS);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Delete_Receipt", receiptIDS, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string ExecutePalletizing(string receiptID, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptDetailLpnBLL(pubParasInfo).ExecutePalletizing(receiptID);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Palletizing_Receipt", receiptID, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public DataSet GetAdjustmentAllInfo(PubParasInfo pubParasInfo)
        {
            try
            {
                AdjustmentBLL adjustment = new AdjustmentBLL(pubParasInfo);
                return adjustment.GetAllAdJustMentInfo();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return null;
        }

        public AdjustmentInfo GetAdjustmentInfoByID(string id, PubParasInfo pubParasInfo)
        {
            AdjustmentInfo adjustment = null;
            try
            {
                adjustment = new AdjustmentBLL(pubParasInfo).GetAdJustMentInfoByID(id);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return adjustment;
        }

        public DataSet GetAdjustmentInfoByQueryEntity(AdjustmentQueryEntity obj, PubParasInfo pubParasInfo)
        {
            try
            {
                AdjustmentBLL adjustment = new AdjustmentBLL(pubParasInfo);
                return adjustment.GetAdJustMentInfoByQueryEntity(obj);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return null;
        }

        public DataSet GetAllReceiptInfo(PubParasInfo pubParasInfo)
        {
            try
            {
                ReceiptBLL receiptBll = new ReceiptBLL(pubParasInfo);
                return receiptBll.GetAllInfo();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return null;
        }

        public ReceiptInfo GetReceiptInfoByID(string receiptID, ReceiptDetailQueryEntity receiptDetailQueryEntity, PubParasInfo pubParasInfo)
        {
            ReceiptInfo receiptInfo = new ReceiptInfo();
            try
            {
                ReceiptBLL receiptBll = new ReceiptBLL(pubParasInfo);
                return receiptBll.GetReceiptInfoByID(receiptID, receiptDetailQueryEntity);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return receiptInfo;
        }

        public ReceiptInfo GetReceiptInfoByID4Exec(string receiptID, PubParasInfo pubParasInfo)
        {
            ReceiptInfo receiptInfo = new ReceiptInfo();
            try
            {
                ReceiptBLL receiptBll = new ReceiptBLL(pubParasInfo);
                return receiptBll.GetReceiptInfoByID4Exec(receiptID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return receiptInfo;
        }

        public DataSet GetReceiptInfoByQueryEntity(ReceiptQueryEntity receiptQuery, PubParasInfo pubParasInfo)
        {
            try
            {
                ReceiptBLL receiptBll = new ReceiptBLL(pubParasInfo);
                return receiptBll.GetReceiptInfoByQueryEntity(receiptQuery);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return null;
        }

        public ReceiptInfo ImporFormSo(string soID, List<string> lineID, string vreceiptID, string maxLineID, string receiptType, PubParasInfo pubParasInfo)
        {
            ReceiptInfo receiptInfo = new ReceiptInfo();
            try
            {
                ReceiptBLL receiptBll = new ReceiptBLL(pubParasInfo);
                return receiptBll.ImporFormSo(soID, lineID, vreceiptID, maxLineID, receiptType);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return receiptInfo;
        }

        public string ImportFormPo(string poID, string receiptID, string type, string createdBy, PubParasInfo pubParasInfo)
        {
            string retrunStr = string.Empty;
            try
            {
                retrunStr = new ReceiptBLL(pubParasInfo).ImportFormPo(poID, receiptID, type, createdBy);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Import_Receipt", poID, receiptID, type, createdBy, pubParasInfo);
                return retrunStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return retrunStr;
        }

        public string InsertReceiptInfo(ReceiptInfo receiptInfo, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptBLL(pubParasInfo).InsertReceipt(receiptInfo);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Insert_Receipt", receiptInfo, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string ReceiptRevert(AdjustmentInfo adjustmentInfo, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptBLL(pubParasInfo).ReceiptRevert(adjustmentInfo);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Revert_Receipt", adjustmentInfo, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string RevertPalletizing(string receiptID, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptDetailLpnBLL(pubParasInfo).RevertPalletizing(receiptID);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_UnPalletizing_Receipt", receiptID, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string UpdateReceiptInfo(ReceiptInfo receiptInfo, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new ReceiptBLL(pubParasInfo).UpdateReceipt(receiptInfo);
                new OperationLogBLL(pubParasInfo).Insert("InboundService_Update_Receipt", receiptInfo, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }
    }
}

